package red.cola.common.config.exception;

import lombok.Data;
import red.cola.result.ResultCodeEnum;

/**
 * @Name: ColaException
 * @Author: Cola
 * @Time: 2023/3/6 11:25
 * @Description: ColaException
 */
@Data
public class ColaException extends RuntimeException {

    /*
    状态码
    */
    private Integer code;
    /*
    描述信息
    */
    private String msg;

    public ColaException(Integer code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    /**
     * 接收枚举类型对象
     *
     * @param resultCodeEnum resultCodeEnum
     */
    public ColaException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMessage();
    }

    @Override
    public String toString() {
        return "ColaException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
